<#assign className = table.className>
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.${subpackage};

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.sql.Timestamp;
import java.util.List;
import java.sql.Date;

@TableBind(tableName = "${table.sqlName}")
public class ${className} extends Model<${className}>{
    public static final ${className} dao = new ${className}();

    //columns START
    <#list table.columns as column>
    private String ${column.columnNameUpperCase} = "${column.columnNameLower}";  //${column.remarks}
    </#list>

    <@generateJavaColumns/>
	//columns END

    public List<${className}> findAll() {
        return find("select * from ${table.sqlName}");
    }
    /**
     * @param   where
     * @return  Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from ${table.sqlName}";
        if(StringKit.notBlank(where)){
                sqlExp += " where " + where;
        }
                return Db.find( "select * " +sqlExp );

    }

    public Page<${className}> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from ${table.sqlName}";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select *", sqlExp);
    }
}

<#macro generateJavaColumns>
	<#list table.columns as column>
    public void set${column.columnName}(${column.primitiveJavaType} value) {
        set(${column.columnNameUpperCase}, value);
    }

	public ${column.primitiveJavaType} get${column.columnName}() {
		return get(${column.columnNameUpperCase});
	}
	</#list>
</#macro>

